/*
 * Copyright (C) 2025 Tsingteng MicroSystem
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
#ifndef _NCI_NFCEE_H_
#define _NCI_NFCEE_H_

#include "nci_feature.h"
#include "nci_types.h"
#include "ee_int.h"

#if IS_FEATURE_ON(NCI_FEATURE_EE)

/**
 * @brief NFCEE相关API定义
 * @file nci_nfcee.h
 */

#define NCI_MAX_NFCEE_PROTOCOL_LEN 3
#define NCI_MAX_NFCEE_INFO_LEN 8
#define NCI_MAX_NFCEE_TLVS_LEN 1

#define NCI_EE_STATUS_NTF_UNRECOVERABLE_ERROR         (0x00)
#define NCI_EE_STATUS_NTF_INITIALIZATION_SEQ_START    (0x01)
#define NCI_EE_STATUS_NTF_INITIALIZATION_SEQ_COMPLETE (0x02)

typedef struct {
    uint8_t type;
    uint8_t length;
    uint8_t value[NCI_MAX_NFCEE_INFO_LEN];
} tNCI_EE_TLV;

typedef struct {
    uint8_t nfcee_id;
    tNCI_EE_STATUS status;
    uint8_t num_of_protocol;
    tNCI_EE_PROTOCOLS protocols[NCI_MAX_NFCEE_PROTOCOL_LEN];
    uint8_t num_of_tlvs;
    tNCI_EE_TLV tlvs[NCI_MAX_NFCEE_TLVS_LEN];
    bool nfcc_power_ctrl;
    tNCI_RF_PROTOCOL la_protocol;
    tNCI_RF_PROTOCOL lb_protocol;
    tNCI_RF_PROTOCOL lf_protocol;
    uint8_t conn_id;
} tNCI_NFCEE;

typedef struct {
  uint8_t op;                      /* 添加或删除此entry  */
  uint8_t len;                     /* 后面数据的长度     */
  uint8_t nfcee_id;                /* NFCEE ID          */
  uint8_t tech_mode;               /* 变化的tech模式     */
  tNCI_RF_PROTOCOL protocol;       /* 变化的protocol     */
} tNCI_EE_DISCOVER_REQ_ENTRY;

typedef struct {
  uint8_t num;   /* entry的数量      */
  tNCI_EE_DISCOVER_REQ_ENTRY entrys[NCI_MAX_NFCEE_SIZE]; /* NFCEE的discovery请求*/
} tNCI_EE_DISCOVER_REQ_NTF;

/**
 * @brief 发现NFCEE
 *
 * @param[out] infos 存储NFCEE信息
 * @param[out] count 返回的NFCEE个数
 *
 * @return 成功返回NCI_STATUS_OK，失败返回错误码
*/
tNCI_STATUS nci_nfcee_discover(tNCI_NFCEE *infos, uint8_t *count);
/**
 * @brief 设置NFCEE状态
 *
 * @param nfcee_id 需要控制的NFCEE ID
 * @param mode 切换的模式
 *
 * @return 成功返回NCI_STATUS_OK，失败返回错误码
 */
tNCI_STATUS nci_nfcee_mode_set(uint8_t nfcee_id, tNCI_EE_MODE mode);
/**
 * @brief 设置NFCEE电源状态
 *
 * @param nfcee_id 需要控制的NFCEE ID
 * @param cfg 电源控制配置
 *
 * @return 成功返回NCI_STATUS_OK，失败返回错误码
 */
tNCI_STATUS nci_nfcee_power_and_link_cntrl(uint8_t nfcee_id, tNCI_EE_POWER_AND_LINK_CFG cfg);
/**
 * @brief 处理NFCEE相关的通知
 *
 * @param oid 通知的OID
 * @param data 通知的payload数据，不包含NCI头
 * @param len 通知的payload长度
 */
void nci_nfcee_ntf_handle(uint8_t oid, uint8_t *data, uint16_t len);

#endif /* NCI_FEATURE_EE */
#endif /* _NCI_NFCEE_H_*/
